package com.dmyang.controller;

import com.dmyang.common.pojo.BootstrapTableResult;
import com.dmyang.common.pojo.HyResult;
import com.dmyang.entity.HyTag;
import com.dmyang.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 标签管理Controller
 * Created by brss on 2017/8/6.
 */
@RequestMapping("tag")
@Controller
public class TagController {

    @Autowired
    private TagService tagService;

    /**
     * 列出所有的分类（分页）
     * @param offset
     * @param limit
     * @return
     */
    @RequestMapping("/list")
    @ResponseBody
    public BootstrapTableResult showTagList(Integer offset,Integer limit){
        BootstrapTableResult result = tagService.showTagList(offset, limit);
        return result;
    }

    /**
     * 新增一条分类
     * @param tag
     * @return
     */
    @RequestMapping("/add")
    @ResponseBody
    public HyResult addTag(HyTag tag){
        try {
            HyResult result = tagService.addTag(tag);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return HyResult.build(500,"新增失败！");
        }
    }

    /**
     * 修改一条分类
     * @param tag
     * @return
     */
    @RequestMapping("/modify")
    @ResponseBody
    public HyResult modifyTag(HyTag tag){
        try {
            HyResult result = tagService.modifyTag(tag);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return HyResult.build(500,"修改失败！");
        }
    }

    @RequestMapping("/delete")
    @ResponseBody
    public HyResult deleteTag(String ids){
        try {
            HyResult result = tagService.deleteTag(ids);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return HyResult.build(500,"删除失败！");
        }
    }

}
